import java.io.IOException;

import mapper.MaxTemperatureMapper;

import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.junit.Test;


public class MaxTemperatureMapperTest {

	@Test
	public void processValidRecord() throws IOException{
		
		Text value = new Text("0029029070999991901010106004+64333+023450FM-12+"
				+ "000599999V0202701N015919999999N0000001N9-00781+99999102001ADDGF108991999999999999999999");
		new MapDriver<LongWritable, Text, Text, IntWritable>()
			.withMapper(new MaxTemperatureMapper())
			.withInputKey(new LongWritable(1l))
			.withInputValue(value)
			.withOutput(new Text("1950"), new IntWritable(-11))
			.runTest();
		
	}
	
	@Test
	public void ignoresMissing() throws IOException{
		
		Text value = new Text("0029029070999991901010106004+64333+023450FM-12+"
				+ "000599999V0202701N015919999999N0000001N9-00781+99999102001ADDGF108991999999999999999999");
		new MapDriver<LongWritable, Text, Text, IntWritable>()
			.withMapper(new MaxTemperatureMapper())
			.withInputKey(new LongWritable(1l))
			.withInputValue(value)
			.runTest();
		
	}
}
